package com.obst.tracenote.util;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.util.Log;

public class ReverseGeocoder {

	final String tag = "ReverseGeocode";

	public String point2address(double latitude, double longitude, Context context) throws IOException{

		String string = new String();

		Log.d(tag, "Start point2adress");
		Geocoder geocoder = new Geocoder(context, Locale.KOREA);
		List<Address> list_address = geocoder.getFromLocation(latitude, longitude, 5);

		if (!list_address.isEmpty()){

			Address address = list_address.get(0);
			StringBuffer strbuf = new StringBuffer();

			String buf;
			for (int i = 0; (buf = address.getAddressLine(i)) != null; i++){
				Log.d(tag, "loop no."+i);
				strbuf.append(buf);
			}

			string = strbuf.toString();

		}

		else {
			Log.d(tag, "Fail Geocoding");
		}

		Log.d(tag, string);
		return string;
	}

}
